<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>阿里云VOD基本信息修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <link rel="shortcut icon" href="/static/favicon.ico">
    <script src="/static/js/jquery.min.js?v=2.1.4"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/layui/layui.2.7.6.js"></script>
    <script src="/static/js/base.js"></script>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form"  action="" lay-filter="formFilter">
                        <div class="layui-row layui-col-space10 layui-form-item">
                            <div class="layui-col-lg6">
                                <label class="layui-form-label layui-required">视频名称：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" lay-verify="required" placeholder="请输入视频名称"
                                           autocomplete="off" class="layui-input" maxlength='60'
                                           value="">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">封面图</label>
                            <div class="layui-input-block">
                                <div class="layui-upload-drag" onclick="upload('thumbnail')">
                                    <i class="layui-icon"></i>
                                    <p>点击上传图片</p>
                                    <div class="layui-hide" id="uploadView">
                                        <hr>
                                        <img src="" alt="上传成功后渲染" style="max-width: 196px">
                                    </div>
                                </div>
                                <input type="hidden" name="cover" value="" autocomplete="off" placeholder=""  class="layui-input">
                                <div class="layui-hide" id="uploadView">
                                    <img src="" id="cover" alt="上传成功后渲染" style="max-width: 196px">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row layui-col-space10 layui-form-item">
                            <div class="layui-col-lg6">
                                <label class="layui-form-label">简介：</label>
                                <div class="layui-input-block">
                                        <textarea class="layui-textarea" name="desc" placeholder="请输入简介，200字以内"
                                                  style="resize: none;"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="radio" name="status" value="1" title="上架" checked>
                                <input type="radio" name="status" value="0" title="下架">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id" lay-verify="required" >
                                <button type="button" class="layui-btn" id="submit" lay-submit lay-filter="mySubmit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/static/aliyun-upload-sdk-1.5.3/aliyun-upload-sdk-1.5.3.min.js"></script>
<script src="/static/aliyun-upload-sdk-1.5.3/lib/es6-promise.min.js"></script>
<script src="/static/aliyun-upload-sdk-1.5.3/lib/aliyun-oss-sdk-6.17.1.min.js"></script>
<script>
    //兼容IE11
    if (!FileReader.prototype.readAsBinaryString) {
        FileReader.prototype.readAsBinaryString = function (fileData) {
            var binary = "";
            var pt = this;
            var reader = new FileReader();
            reader.onload = function (e) {
                var bytes = new Uint8Array(reader.result);
                var length = bytes.byteLength;
                for (var i = 0; i < length; i++) {
                    binary += String.fromCharCode(bytes[i]);
                }
                //pt.result  - readonly so assign binary
                pt.content = binary;
                pt.onload()
            }
            reader.readAsArrayBuffer(fileData);
        }
    }
    var uploader = null,file,env='{$env}'

    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload', 'table', 'tree', 'element'], function () {
        var $ = layui.$
            , upload = layui.upload,
            form = layui.form,
            tree = layui.tree,
            element = layui.element,
            table = layui.table;
        element.init();
        var id = getQueryVariable('id')
        if(id){
            $.ajax({
                url:"/admin/vod/upload",
                type:"get",
                async:false,
                dataType:'json',
                headers:{
                    'token':localStorage.getItem('hypercmfname')+'_'+localStorage.getItem('token'),
                    'accept':'*/*'
                },
                data:{
                    'id' : id,
                    'opentype':'edit'
                },
                success:function(res){
                    if(res.code==1){
                        var data = res.data.info
                        form.val('formFilter', {
                            "id": data.id,
                            "title": data.title,
                            "desc": data.desc,
                            "cover": data.cover,
                        });
                        if(data.cover!=''){
                            layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', data.cover);
                        }
                    }else{
                        layer.msg(res.msg)
                    }
                },
                fail:function(){
                    layer.msg('网络异常')
                }
            })
        }


        form.on('submit(mySubmit)', function (data) {
            var i = layer.load()
            var field = data.field;
            field.opentype='edit'
            $.ajax({
                url:"/admin/vod/upload",
                type:"POST",
                dataType: 'json',
                data:field,
                async:false,
                headers:{
                    'token':localStorage.getItem('hypercmfname')+'_'+localStorage.getItem('token'),
                    'accept':'*/*'
                },
                success:function(res){
                    if(res.code==1){
                        layer.msg('操作成功',{
                            icon: 1,
                            time: 2000 //1秒关闭（如果不配置，默认是3秒）
                        },function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            layer.close(i)
                            parent.layer.close(index);
                            parent.layui.table.reload('dataTable');
                        })

                    }else{
                        layer.msg(res.msg)
                        layer.close(i)
                    }

                },
                fail:function(){
                    layer.msg('网络异常')
                    layer.close(i)
                },

            })
        });


    })
    function upload(from=''){
        layui.layer.open({
            title: '选择图片',
            type: 2,
            shadeClose:true,
            area: ['90%','90%'],
            content: '/admin/public/image_list.html?from='+from
        })
    }
    //layer弹出的子页面传值到当前页面
    function GetChildValue(data,from=''){
        if(from == 'video'){
            $("input[name=video]").attr("value",data[0].id)
        }else if(from == 'thumbnail'){
            console.log(from,data)

            $("input[name=cover]").attr("value",data[0].url)
            layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', data[0].url);
        }
    }

</script>

</html>